package michaelgame.level;

import java.awt.Point;
import java.util.Random;
import michaelgame.Constants;
import michaelgame.sprite.BulletTracker;
import michaelgame.sprite.LifeTracker;
import framework.Level;


/**
 * 
 * @author Michael Deng
 * @author Howard Chung
 * 
 */
public class Level2 extends Level {
    private int myCount;
    private Random myRandom;
    private int myWidth;
    private final int myNextLevelIfWin = 3;
    private final int myNextLevelIfLose = 5;

    @Override
    protected int testWinCondition () {
        // if bullets > 100
        if (((BulletTracker) getMySprites().get("BulletTracker").get(0)).getCurrentBullets() >= 100) {
            return myNextLevelIfWin;
        }
        return -1;
    }

    @Override
    protected int testLoseCondition () {
        // if we run out of life
        if (((LifeTracker) getMySprites().get("LifeTracker").get(0)).getCurrentLives() <= 0) {
            return myNextLevelIfLose;
        }
        return -1;
    }

    @Override
    protected void levelBehavior () {
        myCount++;
        if (myCount % 25 == 0) {
            int randInt = myRandom.nextInt(myWidth);
            loadSprite("Bullet", new Point(randInt, 0));
        }

    }

    @Override
    protected void initializeLevel () {
        myCount = 0;
        myRandom = new Random();
        myWidth = Constants.SIZE.width;
    }

    @Override
    protected void loadLevelObjects () {
        loadSprite("BulletTracker", new Point(0, 0));
        loadSprite("LifeTracker", new Point(0, 0));
        loadCollision("BossBullet");
        loadSprite("Player", new Point(0, 0));

    }

}